const fs = require('fs')
let data = `我是从数据库获取的数据，我要保存起来11\n`

let writeStream = fs.createWriteStream('output.txt')

writeStream.write(data, 'utf8')

//标记写入完成
writeStream.end()

//接收广播表示写入完成
writeStream.on(`finish`, () => {
  console.log(`写入完成`)
})

writeStream.on(`error`, () => {
  console.log(`写入失败`)
})